﻿namespace WMS6.Web
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Web;
    using WMS6.Web.RoleFunctionServiceRef;

    public class RoleFunctionServiceClientProxy : BasePage
    {
        public string DeleteRoleAndRoleFunction(List<string> roleID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (RoleFunctionServiceClient client = new RoleFunctionServiceClient("WSHttpBinding_IRoleFunctionService"))
            {
                return client.DeleteRoleAndRoleFunction(roleID, pubParasInfo);
            }
        }

        public DataSet GetAllFunctionList()
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (RoleFunctionServiceClient client = new RoleFunctionServiceClient("WSHttpBinding_IRoleFunctionService"))
            {
                return client.GetAllFunctionList();
            }
        }

        public static RoleFunctionServiceClientProxy GetInstance()
        {
            return new RoleFunctionServiceClientProxy();
        }

        public List<string> GetOperationByUserIDAndFunctionID(string userID, string functionID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (RoleFunctionServiceClient client = new RoleFunctionServiceClient("WSHttpBinding_IRoleFunctionService"))
            {
                return client.GetOperationByUserIDAndFunctionID(userID, functionID, pubParasInfo);
            }
        }

        public DataSet GetRoleAndRoleFunctionDataByRoleId(string roleID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (RoleFunctionServiceClient client = new RoleFunctionServiceClient("WSHttpBinding_IRoleFunctionService"))
            {
                return client.GetRoleAndRoleFunctionDataByRoleId(roleID, pubParasInfo);
            }
        }

        public DataSet GetRoleFunctionData(string id, string Type)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (RoleFunctionServiceClient client = new RoleFunctionServiceClient("WSHttpBinding_IRoleFunctionService"))
            {
                return client.GetRoleFunctionData(id, Type, pubParasInfo);
            }
        }

        public DataSet GetRoleMenuData(string userID, string isglobal, string language)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (RoleFunctionServiceClient client = new RoleFunctionServiceClient("WSHttpBinding_IRoleFunctionService"))
            {
                return client.GetRoleMenuData(userID, isglobal, pubParasInfo);
            }
        }

        public DataSet GetWHDataByUserID()
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (RoleFunctionServiceClient client = new RoleFunctionServiceClient("WSHttpBinding_IRoleFunctionService"))
            {
                return client.GetWHDataByUserID(pubParasInfo.UserID, pubParasInfo);
            }
        }

        private PubParasInfo InitPubParasInfo()
        {
            if (base.UserInfo != null)
            {
                return new PubParasInfo { UserID = base.UserInfo.UserID, UserLanguage = base.UserInfo.Preference.Lang, CurrentWH = base.UserInfo.CurrentWH };
            }
            HttpContext.Current.Response.Redirect("../Login.aspx?from=Logout", true);
            return null;
        }

        public string UpdateRoleFunctionAndOperationByRoleGID(string type, RoleInfo role, List<string> FunctionTrueList, List<string> FunctionFalseList, List<string> OperationTrueList, List<string> OperationFalseList, string strCopyName)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (RoleFunctionServiceClient client = new RoleFunctionServiceClient("WSHttpBinding_IRoleFunctionService"))
            {
                return client.UpdateRoleFunctionAndOperationByRoleGID(type, role, FunctionTrueList, FunctionFalseList, OperationTrueList, OperationFalseList, strCopyName, pubParasInfo);
            }
        }
    }
}

